<template>
    <view class="content">
        <!--产品，客户列表 -->
        <customersTow
            ref="customersTow"
            @setGoodsThree="setGoodsThree"
            @setCustomInfo="setCustomInfo"
            @addCustomer="addCustomer"
            @upDownClick="upDownClick"
            :md="mdKh"
			:customerName="customerName"
        ></customersTow>

        <!-- 客户详情页面 -->
        <customersThree
            ref="customersThree"
            v-show="curIndex == 1"
            :md="mdKh"
            @removeCustom="removeCustom"
            @bill="bill"
            @editCustomer="editCustomer"
            @updataCustomList="updataCustomList"
        >
        </customersThree>

        <!-- 添加/编辑客户 -->
        <customersAdd
            ref="customersAdd"
            v-show="curIndex == 2"
            :md="mdKh"
            :actType="actType"
            @addCustomSuccess="addCustomSuccess"
        >
        </customersAdd>

        <!-- 导入客户窗口 -->
        <importCustomers ref="importCustomers"></importCustomers>

        <!-- 上传下载菜单 -->
        <upAndDownLoadMenu
            ref="upAndDownLoadMenu"
            :md="mdKh"
            @showUploadCustomWin="showUploadCustomWin"
        ></upAndDownLoadMenu>
    </view>
</template>

<script>

import customersTow from "../../components/customers/CustomersTow.vue";

import customersThree from "../../components/customers/CustomersThree.vue";

import lang from "../../js/conf/Lang.js";
import staticConst from "../../js/const/StaticConst.js";
import goPage from "../../js/GoPage.js";

import goodsAdd from "../../components/goods/GoodsAdd.vue";

import eventCtrl from "../../js/event/EventCtrl.js";
import goodsCtrl from "../../js/gd/GoodsCtrl.js";


import customCtrl from "../../js/custom/CustomCtrl.js";

import upAndDownLoadMenu from "../../components/comm/UpAndDownLoadMenu.vue";

import importCustomers from "../../components/customers/ImportCustomers.vue";

import customersAdd from "../../components/customers/CustomersAdd.vue";

export default {
    components: {
        customersTow,
        customersThree,
        upAndDownLoadMenu,
        importCustomers,
        customersAdd,
    },
    data() {
        return {
            curPage: staticConst.YY_GK,
            actType: 0, // 0:新增客户 1：编辑编辑
            isNotData: false, // 没有数据
            mdKh: staticConst.YY_GK, //模块
            curIndex: 1, //1,
			
			customerName:"",
        };
    },

    onLoad(opt) {
		if(opt.customerName)
			this.customerName = opt.customerName;
	},

    onShow() {},

    onHide() {},

    onUnload() {},

    onReady() {
        if (customCtrl.addCustomer == 1) {
            customCtrl.addCustomer = 0; //用完，重置
            this.addCustomer();
        } else {
            this.$refs.customersTow.initData();
        }
    },

    methods: {
        /****显示上传产品列表窗口****/
        showUploadCustomWin() {
            this.$refs.importCustomers.show("show");
        },

        /*****显示上传下载菜单****/
        upDownClick() {
            this.isClickUpDownBtn = true;
            this.$refs.upAndDownLoadMenu.show();
        },

        /***点击产品列表处理**/
        setGoodsThree(data) {
            // this.$refs.receiptInfo.addGoodsReceipt(data);
        },

        /****设置开单用户*******/
        setCustomInfo(data) {
            // this.$refs.receiptInfo.getCustomInfo(data,isCheckOut);
            /****选中客户******/
            this.curIndex = 1;
            this.$refs.customersThree.loadCustomInfo(data);
        },

        /****删除客户*****/
        removeCustom(id) {
            this.$refs.customersTow.removeCustom(id);
        },

        /****开单操作****/
        bill(data) {
            customCtrl.setBillCustom(data);
            this.$refs.changeTab.bill("1");
        },

        /****添加客户****/
        addCustomer() {
            this.curIndex = 2;
            this.actType = 0;
            this.$refs.customersAdd.init();
        },

        /****编辑客户****/
        editCustomer(data) {
            this.curIndex = 2;
            this.actType = 1;
            this.$refs.customersAdd.init(data);
        },

        /*******添加修改客户成功*******/
        addCustomSuccess(data) {
            this.curIndex = 1;
            if (data.act == 0) {
                //新增客户详情
                this.$refs.customersTow.addNewCustomer();
            } //编辑客户详情
            else {
                this.$refs.customersThree.editCustomInfo(data.id);
            }
        },

        /***编辑客户更新客户****/
        updataCustomList(data) {
            this.$refs.customersTow.updataCustomList(data);
        },
    },
};
</script>
<style lang="scss">
.content {
    display: flex;
    justify-content: flex-start;
    min-width: 820px;
    height: 100%;
    position: relative;
}
</style>